package com.sk.skplanet.commute.controllers;

import android.content.Context;
import android.util.Log;
import android.widget.RelativeLayout.LayoutParams;

import com.sk.skplanet.commute.actions.Actions;
import com.sk.skplanet.commute.exceptions.LogManager;
import com.skp.Tmap.TMapPoint;
import com.skp.Tmap.TMapView;

public class TmapViewController {

	static TMapView mMapView;

	public static TMapView createTmapView(Context context) {

		mMapView = new TMapView(context);
		mMapView.setZOrderOnTop(true);
		TmapViewController.configureMapView(mMapView);
		{
			LayoutParams layoutParams_button = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
			layoutParams_button
					.setMargins(Actions.DPFromPixel(10), 0, Actions.DPFromPixel(10), Actions.DPFromPixel(10));
			mMapView.setLayoutParams(layoutParams_button);
			mMapView.setMinimumHeight(200);
			mMapView.setMinimumWidth(200);
		}
		mMapView.setIconVisibility(true);
		mMapView.setZoomLevel(15);

		mMapView.setZoomLevel(13);

		return mMapView;

	}

	public static void configureMapView(final TMapView mMapView) {

		new Thread() {
			@Override
			public void run() {

				mMapView.setSKPMapApiKey("99e83bb1-39ae-36dd-89bc-487aeb36591a");
				mMapView.setLanguage(mMapView.LANGUAGE_KOREAN);
				Log.i("map_auth", "success");

			}
		}.start();
	}

	public static void mapZoomIn() {
		mMapView.MapZoomIn();
	}

	public static void mapZoomOut() {
		mMapView.MapZoomOut();
	}

	public static void getZoomLevel() {
		// int nCurrentZoomLevel = mMapView.getZoomLevel();

		// Common.showAlertDialog(this, "", "���� Zoom Level : " + Integer.toString(nCurrentZoomLevel));

	}

	public static void getLocationPoint() {
		TMapPoint point = mMapView.getLocationPoint();

		double Latitude = point.getLatitude();
		double Longitude = point.getLongitude();

		LogManager.printLog("Latitude " + Latitude + " Longitude " + Longitude);

		// String strResult = String.format("Latitude = %f Longitude = %f", Latitude, Longitude);
		//
		// Common.showAlertDialog(this, "", strResult);

	}

	public static void setLocationPoint(double mLatitude, double mLongitude) {

		LogManager.printLog("setLocationPoint " + mLatitude + " " + mLongitude);

		mMapView.setLocationPoint(mLongitude, mLatitude);
		mMapView.setCenterPoint(mLongitude, mLatitude);
	}

}
